import { _decorator, Component, Node, SpriteAtlas, Sprite, NodeEventType } from 'cc';
import { Igame } from './Igame';

const { ccclass, property } = _decorator;

@ccclass('pattern')
export class pattern extends Component {

    @property(SpriteAtlas)
    colorAtlas: SpriteAtlas

    
    igame:Igame

    onLoad(){
        this.node.on(NodeEventType.TOUCH_START,this.touchCheck,this)
    }
    onDestory(){
        this.node.off(NodeEventType.TOUCH_START,this.touchCheck,this)
    }

    touchCheck() {
        let sprite = this.node.getComponent(Sprite)
        this.igame.click(sprite.spriteFrame.name);       
    }
    //初始化方块
    initPattern(key: string){
        let frames = this.colorAtlas.spriteFrames
        let sprite = this.node.getComponent(Sprite)
        sprite.spriteFrame = frames[key]
    }

}

